request('\s is not a CivManager Save File',quitstring,NIL)
CleanUp(20)
ENDIF
ENDIF
/* Load Icon File */
StrCopy(iconname,civdir,ALL)
StrAdd(iconname,'/DefSaveIcon.info',ALL)
IF (buflen := FileLength(iconname)) <> -1
iconfile := Open(iconname,MODE_OLDFILE)
iconbuf := New(buflen)
Read(iconfile,iconbuf,buflen)
Close(iconfile)
ENDIF
StrCopy(iconname,filename,ALL)
StrAdd(iconname,'.info',ALL)
/* Setup notifier */
nreq:=New(SIZEOF notifyrequest) /* memory is cleared */
notifysigbit:=AllocSignal(-1) /* we want to be signalled */
task:=FindTask(0)
nreq.name:='RAM:CIVIL0.SVE' /* fill in structure */
nreq.flags:=NRF_SEND_SIGNAL
nreq.port:=task /* union port/task */
nreq.signalnum:=notifysigbit
notifysig:=Shl(1,notifysigbit)
active:=TRUE
StartNotify(nreq)
/* Load Civilization */
Execute('run CIV1:CivilizationAGA',NIL,NIL)
/* Monitor File Loop */
REPEAT
/* Wait for civilisation to save the game, or a commodities
signal to occur */
sig := Wait(notifysig OR cxsigbit OR SIGBREAKF_CTRL_C)
IF (sig AND notifysig)
/* Signal was a file modification */
IF active
Delay(50) /* Wait 1 second to ensure writing
is completed from civilization */
IF (quitprog := FileLength('RAM:CIVIL0.SVE')) <> -1
copyfromram(filename)
IF buflen
/* If the default icon was successfully read */
iconfile := Open(iconname,MODE_NEWFILE)
Write(iconfile,iconbuf,buflen)
Close(iconfile)
ENDIF
ENDIF
ENDIF
ELSE
/* Signal was from commodities */
WHILE msg := GetMsg(messport)
msgtype:=CxMsgType(msg)
msgid:=CxMsgID(msg)
ReplyMsg(msg)
IF msgtype = CXM_COMMAND
SELECT msgid
CASE CXCMD_DISABLE
active:=FALSE
ActivateCxObj(brokerobj,0)
CASE CXCMD_ENABLE
active:=TRUE
ActivateCxObj(brokerobj,1)
CASE CXCMD_KILL
quitprog:=-1
CASE CXCMD_UNIQUE
quitprog:=-1
ENDSELECT
ENDIF
ENDWHILE
IF (sig AND SIGBREAKF_CTRL_C)
quitprog := -1
ENDIF
ENDIF
UNTIL quitprog = -1
FreeSignal(notifysigbit)
DeleteCxObjAll(brokerobj)
WHILE (msg:=GetMsg(messport))
ReplyMsg(msg)
ENDWHILE
DeleteMsgPort(messport)
IF request('Thank you for using CivManager V1.3\nBy Paul Hickman (ph@doc.ic.ac.uk)\n\nShall I delete the files in RAM:\nBefore Quitting?',' Yes | No ',NIL)
DeleteFile('RAM:CIVIL0.SVE')
DeleteFile('RAM:CIVIL0.MAP')
ENDIF
EXCEPT
IF sig<>-1 THEN FreeSignal(notifysigbit)
IF brokerobj
DeleteCxObjAll(brokerobj)
WHILE (msg:=GetMsg(messport))
ReplyMsg(msg)
ENDWHILE
DeleteMsgPort(messport)
ENDIF
SELECT exception
CASE ER_OPEN; request('Error: Could Not Open A File',quitstring,NIL)
CASE ER_READ; request('Error: Could Not Read A File',quitstring,NIL)
CASE ER_WRITE; request('Error: Could Not Write To A File',quitstring,NIL)
CASE ER_MEM; request('Error: Out Of Memory Error',quitstring,NIL)
CASE ER_NOSIG; request('Error: Could Not Allocate Signal Bit',quitstring,NIL)
CASE ER_NONOTIFY; request('Error: Cannot watch \aRAM:CIVIL0.SVE\a',quitstring,NIL)
CASE ER_CIVLOAD; request('Error: Could Not Load Civilization',quitstring,NIL)
CASE ER_OPENLIB; request('Error: Could Not Open Required Libraries',quitstring,NIL)
CASE ER_MSGPORT; request('Error: Could Not Create A Message Port',quitstring,NIL)
CASE ER_BROKER; /* Not an error - this is "run twice" quitting the 2nd copy */
CASE ER_LOCK; request('Error: Could Not Lock Directory',quitstring,NIL)
CASE ER_ASSIGN; request('Error: Could Not Assign CIV?:',quitstring,NIL)
CASE ER_FONT; request('Error: Could Not Assign FONTS:',quitstring,NIL)
DEFAULT; request('Error: An IO Error Has Occured',quitstring,NIL)